import request from '../utils/request'

// 获取分类列表
export function getCategories() {
  return request({
    url: '/circle/categories/',
    method: 'GET'
  })
}

// 获取帖子列表
export function getPosts(params) {
  return request({
    url: '/circle/posts/',
    method: 'GET',
    params
  })
}

// 获取帖子详情
export function getPostDetail(id) {
  return request({
    url: `/circle/posts/${id}/`,
    method: 'GET'
  })
}

// 创建帖子
export function createPost(data) {
  return request({
    url: '/circle/posts/create/',
    method: 'POST',
    data
  })
}

// 更新帖子
export function updatePost(id, data) {
  return request({
    url: `/circle/posts/${id}/`,
    method: 'PUT',
    data
  })
}

// 删除帖子
export function deletePost(id) {
  return request({
    url: `/circle/posts/${id}/`,
    method: 'DELETE'
  })
}

// 获取帖子评论
export function getPostComments(id, params) {
  return request({
    url: `/circle/posts/${id}/comments/`,
    method: 'GET',
    params
  })
}

// 创建帖子评论
export function createPostComment(id, data) {
  return request({
    url: `/circle/posts/${id}/comments/`,
    method: 'POST',
    data
  })
}

// 点赞帖子
export function likePost(id) {
  return request({
    url: '/circle/likes/',
    method: 'POST',
    data: {
      post: id
    }
  })
}

// 取消点赞帖子
export function unlikePost(id) {
  return request({
    url: '/circle/likes/',
    method: 'DELETE',
    data: {
      post: id
    }
  })
}

// 删除评论
export function deleteComment(id) {
  return request({
    url: `/circle/comments/${id}/`,
    method: 'DELETE'
  })
}